var http = require("http");
var fs = require("fs");

http.createServer(function(req,res){
    if(req.url == "/"){
        fs.readFile("./titles.json",function(err,result){
            if(err){
                throw err;
            }

            var entries = JSON.parse(result.toString());
            console.log(entries);
            var output = "<html><head><title>读取书本标题</title></head><body>";
            for( var i in entries){
                console.log(entries[i]);
               output += "<div>" + entries[i].title + "</div>";
            }
            output += "</body></html>";
            res.end(output);
        });
    }
}).listen(8899);